package com.pmy.service;

import com.pmy.dao.ProviderMapper;
import com.pmy.pojo.Provider;
import com.pmy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "ProviderServiceImpl")
public class ProviderServiceImpl implements ProviderService{
    @Autowired
    ProviderMapper providerMapper;

    @Override
    public List<Provider> queryAll(String proCode, String proName, int currentPageNo, int pageSize) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("proCode",proCode);
        map.put("proName",proName);
        map.put("currentPageNo",currentPageNo);
        map.put("pageSize",pageSize);

        List<Provider> list = providerMapper.queryAll(map);

        return list;
    }

    @Override
    public int getProviderCount(String proCode, String proName) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("proCode",proCode);
        map.put("proName",proName);
        int count = providerMapper.getProviderCount(map);
        return count;
    }

    @Override
    public Provider getProviderById(int id) {
        return providerMapper.getProviderById(id);
    }

    @Override
    public int addProvider(Provider provider){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("proCode",provider.getProCode());
        map.put("proName",provider.getProName());
        map.put("proDesc",provider.getProDesc());
        map.put("proContact",provider.getProContact());
        map.put("proPhone",provider.getProPhone());
        map.put("proAddress",provider.getProAddress());
        map.put("proFax",provider.getProFax());
        int addProvider = providerMapper.addProvider(map);
        return addProvider;
    }

    @Override
    public int deleteProviderById(int id) {
        return providerMapper.deleteProviderById(id);
    }

    @Override
    public int updateProviderById(Provider provider) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("proCode",provider.getProCode());
        map.put("proName",provider.getProName());
        map.put("proDesc",provider.getProDesc());
        map.put("proContact",provider.getProContact());
        map.put("proPhone",provider.getProPhone());
        map.put("proAddress",provider.getProAddress());
        map.put("proFax",provider.getProFax());
        map.put("id",provider.getId());
        int updateProviderById = providerMapper.updateProviderById(map);
        return updateProviderById;
    }

    @Override
    public List<String> getProviderName() {
        return providerMapper.getProviderName();
    }
}
